package com.example.purchase.view.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;

import com.example.purchase.R;
import com.example.purchase.databinding.ActivitySplashBinding;
import com.example.purchase.view.base.BaseActivity;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;

public class SplashActivity extends BaseActivity<ActivitySplashBinding> implements View.OnClickListener {

    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEmpty() {

    }

    //修改默认全面屏配置 修改成：启动页配置
    @Override
    protected ImmersionBar createStatusBarConfig() {
        return ImmersionBar.with(this)
                .hideBar(BarHide.FLAG_HIDE_STATUS_BAR)
                .transparentNavigationBar()
                .fullScreen(true);
    }

    @Override
    protected void initClick() {
        dataBinding.timeLayout.setOnClickListener(this);
    }

    @Override
    protected void initTimeOut() {
        Log.e("TAG", "initTimeOut: 我快" );
        countDownTimer = new CountDownTimer(3000, 1000) {
            public void onTick(long millisUntilFinished) {
                dataBinding.time.setText(millisUntilFinished / 1000 + "秒后跳转");
            }
            public void onFinish() {
                startActivity(new Intent(SplashActivity.this,MainActivity.class));
                finish();
            }
        };

        countDownTimer.start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.timeLayout:
                countDownTimer.cancel();
                startActivity(new Intent(SplashActivity.this,MainActivity.class));
                finish();
                break;
        }
    }
}